package com.cy.law.utils;

import org.springframework.data.domain.Sort;

/**
 * @Author: caiqyxyx
 * @Date: 2018/10/8 16:03
 */
public enum JPAOrder {
    DESC("DESC", Sort.Direction.DESC),
    ASC("ASC", Sort.Direction.ASC);

    private String name;
    private Sort.Direction direction;

    JPAOrder(String name, Sort.Direction direction) {
        this.name = name;
        this.direction = direction;
    }

    public static Sort.Direction getDirection(String d) {
        try {
            return JPAOrder.valueOf(d.toUpperCase()).direction;
        } catch (Exception e) {
            return Sort.Direction.ASC;
        }
    }
}